#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <string>
#include <iostream>
#include <stdexcept>
#include <cstring>
#include <sstream>
char* sendBuffer;
long sendBufferSize;

void SendMsg(mqd_t id,const std::string & data)
{
  if(mq_send(id,data.c_str(),data.size(),0)==-1)
    std::cerr<<"无法发送POSIX消息"<<std::endl;
}

std::string ReceiveMsg(mqd_t id)
{
  std::size_t size=mq_receive(id,sendBuffer,sendBufferSize,nullptr);
  return std::string(sendBuffer,size);
}

int main()
{
  mqd_t msgQueue=mq_open("/HBTY_MSGSERVER_CAMERACOLLEGE",O_EXCL | O_RDWR);
  if(msgQueue==-1)
    throw std::runtime_error("无法打开消息队列");
  struct mq_attr attr;
  mq_getattr(msgQueue,&attr);
  sendBufferSize=attr.mq_msgsize;
  sendBuffer=new char[attr.mq_msgsize];

  SendMsg(msgQueue,"Monitor Start");
  delete [] sendBuffer;
}
